package com.odianyun.springboottest.web;

import com.odianyun.db.query.PageVO;
import com.odianyun.project.model.vo.ObjectResult;
import com.odianyun.project.model.vo.PageResult;
import com.odianyun.project.model.vo.Result;
import com.odianyun.project.query.PageQueryArgs;
import com.odianyun.project.support.base.controller.BaseController;
import com.odianyun.springboottest.model.dto.SoPackageDTO;
import com.odianyun.springboottest.model.vo.SoPackageVO;
import com.odianyun.springboottest.service.SoPackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(value="SoPackageController", tags="SoPackage")
@RequestMapping("soPackage")
@RestController
public abstract class AbstractSoPackageController<DTO extends SoPackageDTO> extends BaseController {
    @Resource
    protected SoPackageService service;

	@ApiOperation(value="SoPackage-分页查询")
	@GetMapping("/listPage")
    public PageResult<SoPackageVO> listPage(@RequestBody PageQueryArgs args) {
        PageVO<SoPackageVO> pageVO = service.listPage(args);
        return PageResult.ok(pageVO);
    }

    @ApiOperation("SoPackage-查询")
    @GetMapping("/getById")
    public ObjectResult<SoPackageVO> getById(@RequestParam("id") Long id) {
        SoPackageVO vo = service.getById(id);

        return ObjectResult.ok(vo);
    }

    @ApiOperation("SoPackage-添加")
    @PostMapping("/add")
    public ObjectResult<Long> add(@RequestBody @Valid DTO u) throws Exception {
        notNull(u);

        return ObjectResult.ok(service.addWithTx(u));
    }

    @ApiOperation("SoPackage-修改")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid DTO u) throws Exception {
        notNull(u);
        fieldNotNull(u, "id");

        service.updateWithTx(u);
        return Result.OK;
    }

    @ApiOperation("SoPackage-删除")
    @PostMapping("/delete")
    public Result delete(@RequestBody Long[] ids) throws Exception {
        notNull(ids);

        service.deletesWithTx(ids);
        return Result.OK;
    }
	
}
